package com.demo.redpacket.controller;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @ClassName Test
 * @Description TODO
 * @Author wangmeng
 * @Date 2023/10/21 15:23
 * @Version 1.0
 **/
public class Test {

    public static void main(String[] args) {
        List<member> list1 = new ArrayList<>();
        list1.add(new member(1,"wangmeng"));
        list1.add(new member(2,"kabuda"));
        list1.add(new member(3,"zhangsan"));
        list1.add(new member(4,"lisi"));
        list1.add(new member(4,""));
        list1.add(new member(4,""));
        List<member> list2 = new ArrayList<>();
        Iterator<member> iterator= list1.iterator();
        while (iterator.hasNext()) {
            member member = iterator.next();
            if (member.getAge() == 4) {
                // 删除元素
                iterator.remove();
                member.setName("red");
                list2.add(member);
            }else{
                member.setAge(1212);
            }
        }
        System.out.println(list2);
        System.out.println(list1);
    }


}
